package cn.airfei.netty.nettyexample.inboundhandlerandoutboundhandler;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;

import java.util.List;

/**
 * @description:
 * @author: air
 * @create: 2021-01-22 11:29
 */
public class MyByteToLongDecoder extends ByteToMessageDecoder {

    /**
     *
     * @param ctx
     * @param in
     * @param out
     * @throws Exception
     */
    @Override
    protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
        System.out.println("MyByteToLongDecoder 被调用");

        // long 占用8自己
        if (in.readableBytes()>=8){
            out.add(in.readLong());
        }
    }
}
